package stanaGUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListCellRenderer;
import javax.swing.Renderer;
import javax.swing.RepaintManager;
import javax.swing.border.Border;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeries;
import com.linuxense.javadbf.DBFException;
import com.linuxense.javadbf.DBFField;
import com.linuxense.javadbf.DBFReader;

import stanaGUI.Hierarchical.AlgoHierarchicalClustering;
import stanaGUI.Hierarchical.Cluster;
import stanaGUI.Hierarchical.Item;
import stanaGUI.KMeans.AlgoKMeans;
import stanaGUI.MainWindow.MenuItemActionListener;
import stanaGUI.ComboSelections;

public class Welcome extends JFrame implements Printable, ActionListener, ItemListener
{
	private JButton csvButton1;
	private JButton printButton10;
	private JButton bigDbfButton11;
	private JButton bigOpenButton12;
	private JButton saveButton13;
	private JButton bigCsvButton3;
	private JButton openButton4;
	private JButton dbfButton5;
	private JButton metaButton6;
	private JButton dataButton7;
	private JButton chartsButton8;
	private JButton reportButton9;
	private JMenu jMenu1;
	private JMenu jMenu2;
	private JMenu jMenu3;
	private JMenu jMenu4;
	private JMenu jMenu6;
	private JMenuBar jMenuBar1;
	private JMenuItem smallOpenItem1;
	private JMenuItem smallChartItem10;
	private JMenuItem smallReportItem11;
	private JMenuItem stanaItem12;
	private JMenuItem aboutStana13;
	private JMenuItem smallSaveItem14;
	private JMenuItem smallPrintItem2;
	private JMenuItem exitMenuItem3;
	private JMenuItem smallCsvItem4;
	private JMenuItem smallDbfItem5;
	private JMenuItem KmeansItem6;
	private JMenuItem HierarchicalItem7;
	private JMenuItem smallMetaItem8;
	private JMenuItem smallDataItem9;
	private JToolBar jToolBar1;
	private JToolBar jToolBar2;
	private JLabel lchart;
	private JLabel lselect;
	private JLabel lconfig;
	private JLabel ltitle;
	private JLabel xaxis1;
	private JLabel yaxis1;
	private JPanel panel = new JPanel(null);
	private JPanel panel32 = new JPanel(null);
	private JPanel panelSchema = new JPanel(null);
	private JPanel chartsViewPanel = new JPanel(null); 
	static Vector attributesList = new Vector(4);
	static String[] columnsTypeList;
	static Vector indexList = new Vector(4);
	public static JTable dataTableValue;
	public static int index1;
	public static int index2;
	static double euclideanVal = 0;
	static double cityBlockVal = 0;
	static JFrame clusterDetail = new JFrame("Cluster details");
	
	String[] chartdiagram = { 
			
			"Select Chart",
			"Pie Chart",
			"Histogram",
			"Area Chart",
			"Scatter"
	};

	String[] algoVal = {
			
			"Select Algorithm",
			"K-means",
			"Hierarchical"
	};

	String[] distanceVal = {	
			
			"Select Distance",
			"Euclidean Distance",
			"City Block Distance"
	};
	String[] minClusterValue = { "---", "1", "2", "3", "4", "5"};
	String[] maxClusterValue = { "--", "1", "2", "3", "4", "5"};
	static String[] attributesValue;

	JCheckBox cquantity, cprice, cdate;
	JTextField title, xaxis, yaxis, minimumCluseter, maximumCluster;
	JComboBox chart, algorithm, distance;
	JButton ok, cancel, submit;
	static Font font;
	static String algoNameSelected = "";
	static String chartNameSelected = "";
	static String distanceValSelected = "";
	static String numberOfMaxClusters = "";
	static String numberOfMinClusters = "";
	static String numberOfClusters = "";
	static String chartValue = "";
	JScrollPane filePane = new JScrollPane();
	ActionListener listener = new ButtonActionListener(this, filePane);
	
	// Declare two variables.
	public Welcome()
	{
		initComponents();
		addWindowListener(new WindowAdapter() {
			public void windowOpened(WindowEvent e) {
				Welcome.this.setExtendedState(6);
			}
		});
	}

	private void initComponents()
	{
		this.setTitle("Main Screen --");
		this.jToolBar1 = new JToolBar();//jToolBar1
		this.csvButton1 = new JButton();
		csvButton1.setName("csvButton1");
		this.dbfButton5 = new JButton();
		dbfButton5.setName("dbfButton5");
		this.openButton4 = new JButton();
		openButton4.setName("openButton4");
		this.saveButton13 = new JButton();
		saveButton13.setName("saveButton13");
		this.printButton10 = new JButton();
		printButton10.setName("printButton10");
		this.bigCsvButton3 = new JButton();
		bigCsvButton3.setName("bigCsvButton3");
		this.jToolBar2 = new JToolBar();//jToolBar2
		this.metaButton6 = new JButton();
		metaButton6.setName("metaButton6");
		this.dataButton7 = new JButton();
		dataButton7.setName("dataButton7");
		this.chartsButton8 = new JButton();
		chartsButton8.setName("chartsButton8");
		this.reportButton9 = new JButton();
		reportButton9.setName("reportButton9");
		this.bigDbfButton11 = new JButton();
		bigDbfButton11.setName("bigDbfButton11");
		this.bigOpenButton12 = new JButton();
		bigOpenButton12.setName("bigOpenButton12");
		this.jMenuBar1 = new JMenuBar();
		this.jMenu1 = new JMenu();
		this.jMenu6 = new JMenu();
		this.smallCsvItem4 = new JMenuItem();
		smallCsvItem4.setName("smallCsvItem4");
		this.smallDbfItem5 = new JMenuItem();
		smallDbfItem5.setName("smallDbfItem5");
		this.smallOpenItem1 = new JMenuItem();
		smallOpenItem1.setName("smallOpenItem1");
		this.smallSaveItem14 = new JMenuItem();
		smallSaveItem14.setName("smallSaveItem14");
		this.smallPrintItem2 = new JMenuItem();
		smallPrintItem2.setName("smallPrintItem2");
		this.exitMenuItem3 = new JMenuItem();
		exitMenuItem3.setName("exitMenuItem3");
		this.jMenu2 = new JMenu();
		this.KmeansItem6 = new JMenuItem();
		KmeansItem6.setName("KmeansItem6");
		this.HierarchicalItem7 = new JMenuItem();
		HierarchicalItem7.setName("HierarchicalItem7");
		this.jMenu3 = new JMenu();
		this.smallMetaItem8 = new JMenuItem();
		smallMetaItem8.setName("smallMetaItem8");
		this.smallDataItem9 = new JMenuItem();
		smallDataItem9.setName("smallDataItem9");

		this.smallChartItem10 = new JMenuItem();
		smallChartItem10.setName("smallChartItem10");

		this.smallReportItem11 = new JMenuItem();
		smallReportItem11.setName("smallReportItem11");

		this.jMenu4 = new JMenu();
		this.stanaItem12 = new JMenuItem();
		stanaItem12.setName("stanaItem12");

		this.aboutStana13 = new JMenuItem();
		aboutStana13.setName("aboutStana13");


		setDefaultCloseOperation(3);
		this.jToolBar1.setRollover(true);

		this.csvButton1.setIcon(new ImageIcon(getClass().getResource("/csvv24.png")));
		this.csvButton1.setFocusable(false);
		this.csvButton1.setBorder(null);
		this.csvButton1.setHorizontalTextPosition(0);
		this.csvButton1.setVerticalTextPosition(3);
		csvButton1.addActionListener(listener);
		this.jToolBar1.add(this.csvButton1);
		this.jToolBar1.addSeparator();

		this.dbfButton5.setIcon(new ImageIcon(getClass().getResource("/dbff24.png")));
		this.dbfButton5.setFocusable(false);
		this.dbfButton5.setBorder(null);
		this.dbfButton5.setHorizontalTextPosition(0);
		this.dbfButton5.setVerticalTextPosition(3);
		dbfButton5.addActionListener(listener);    
		this.jToolBar1.add(this.dbfButton5);
		this.jToolBar1.addSeparator();

		this.openButton4.setIcon(new ImageIcon(getClass().getResource("/open24.png")));
		this.openButton4.setFocusable(false);
		this.openButton4.setBorder(null);
		this.openButton4.setHorizontalTextPosition(0);
		this.openButton4.setVerticalTextPosition(3);
		openButton4.addActionListener(listener);    
		this.jToolBar1.add(this.openButton4);
		this.jToolBar1.addSeparator();

		this.saveButton13.setIcon(new ImageIcon(getClass().getResource("/save24.png")));
		this.saveButton13.setFocusable(false);
		this.saveButton13.setBorder(null);
		this.saveButton13.setHorizontalTextPosition(0);
		this.saveButton13.setVerticalTextPosition(3);
		saveButton13.addActionListener(listener);    
		this.jToolBar1.add(this.saveButton13);
		this.jToolBar1.addSeparator();

		this.printButton10.setIcon(new ImageIcon(getClass().getResource("/printer24.png")));
		this.printButton10.setFocusable(false);
		this.printButton10.setBorder(null);
		this.printButton10.setHorizontalTextPosition(0);
		this.printButton10.setVerticalTextPosition(3);
		printButton10.addActionListener(listener);    
		this.jToolBar1.add(this.printButton10);
		
		
		//jToolBar2----------------
		this.bigCsvButton3.setIcon(new ImageIcon(getClass().getResource("/csvv64.png")));
		bigCsvButton3.addActionListener(listener); 
		bigCsvButton3.setBorder(null);
		this.jToolBar1.setRollover(true);
		this.jToolBar1.addSeparator();

		this.metaButton6.setIcon(new ImageIcon(getClass().getResource("/metaa24.png")));
		this.metaButton6.setFocusable(false);
		this.metaButton6.setBorder(null);
		this.metaButton6.setToolTipText("Meta Data View");
		this.metaButton6.setMaximumSize(new Dimension(30, 50));
		this.metaButton6.setHorizontalTextPosition(0);
		this.metaButton6.setVerticalTextPosition(3);
		metaButton6.addActionListener(listener);     
		this.jToolBar1.add(this.metaButton6);
		this.jToolBar1.addSeparator();

		this.dataButton7.setIcon(new ImageIcon(getClass().getResource("/data24.png")));
		this.dataButton7.setFocusable(false);
		this.dataButton7.setBorder(null);
		this.dataButton7.setToolTipText("Data View");
		this.dataButton7.setHorizontalTextPosition(0);
		this.dataButton7.setMaximumSize(new Dimension(30, 50));
		this.dataButton7.setVerticalTextPosition(3);
		dataButton7.addActionListener(listener);     
		this.jToolBar1.add(this.dataButton7);
		this.jToolBar1.addSeparator();

		this.chartsButton8.setIcon(new ImageIcon(getClass().getResource("/charts24.png")));
		this.chartsButton8.setFocusable(false);
		this.chartsButton8.setBorder(null);
		this.chartsButton8.setToolTipText("Chart View");
		this.chartsButton8.setHorizontalTextPosition(0);
		this.chartsButton8.setMaximumSize(new Dimension(30,50));
		this.chartsButton8.setVerticalTextPosition(3);
		chartsButton8.addActionListener(listener);     
		this.jToolBar1.add(this.chartsButton8);
		this.jToolBar1.addSeparator();

		this.reportButton9.setIcon(new ImageIcon(getClass().getResource("/report24.png")));
		this.reportButton9.setFocusable(false);
		this.reportButton9.setBorder(null);
		this.reportButton9.setToolTipText("Report View");
		this.reportButton9.setMaximumSize(new Dimension(30,50));
		this.reportButton9.setHorizontalTextPosition(0);
		this.reportButton9.setVerticalTextPosition(3);
		reportButton9.addActionListener(this);     
		this.jToolBar1.add(this.reportButton9);
		this.jToolBar1.addSeparator();

		this.bigDbfButton11.setIcon(new ImageIcon(getClass().getResource("/dbff64.png")));
		bigDbfButton11.addActionListener(listener); 
		bigDbfButton11.setBorder(null);
		jToolBar1.addSeparator();
		
		this.bigOpenButton12.setIcon(new ImageIcon(getClass().getResource("/open64.png")));
		bigOpenButton12.addActionListener(listener); 
		bigOpenButton12.setBorder(null);
		jToolBar1.addSeparator();
		
		//start File Menu
		this.jMenu1.setMnemonic('F');
		this.jMenu1.setText("File");
		this.jMenu6.setText("Import Data");

		this.smallCsvItem4.setAccelerator(KeyStroke.getKeyStroke(86, 8));
		this.smallCsvItem4.setIcon(new ImageIcon(getClass().getResource("/csvv16.png")));
		this.smallCsvItem4.setText("Import CSV file");
		smallCsvItem4.addActionListener(listener);    
		this.jMenu6.add(this.smallCsvItem4);

		this.smallDbfItem5.setAccelerator(KeyStroke.getKeyStroke(68, 8));
		this.smallDbfItem5.setIcon(new ImageIcon(getClass().getResource("/dbff16.png")));
		this.smallDbfItem5.setText("Import DBF file");
		smallDbfItem5.addActionListener(listener);      
		this.jMenu6.add(this.smallDbfItem5);

		this.jMenu1.add(this.jMenu6);

		this.smallOpenItem1.setAccelerator(KeyStroke.getKeyStroke(79, 2));
		this.smallOpenItem1.setIcon(new ImageIcon(getClass().getResource("/open16.png")));
		this.smallOpenItem1.setText("Open");
		smallOpenItem1.addActionListener(listener);      
		this.jMenu1.add(this.smallOpenItem1);

		this.smallSaveItem14.setAccelerator(KeyStroke.getKeyStroke(83, 2));
		this.smallSaveItem14.setIcon(new ImageIcon(getClass().getResource("/save16.png")));
		this.smallSaveItem14.setText("Save");
		smallSaveItem14.addActionListener(listener);        
		this.jMenu1.add(this.smallSaveItem14);

		this.smallPrintItem2.setAccelerator(KeyStroke.getKeyStroke(80, 2));
		this.smallPrintItem2.setIcon(new ImageIcon(getClass().getResource("/printer16.png")));
		this.smallPrintItem2.setText("Print");
		smallPrintItem2.addActionListener(listener);        
		this.jMenu1.add(this.smallPrintItem2);

		this.exitMenuItem3.setAccelerator(KeyStroke.getKeyStroke(88, 2));
		this.exitMenuItem3.setText("Exit");
		exitMenuItem3.addActionListener(listener);        
		this.jMenu1.add(this.exitMenuItem3);
		this.jMenuBar1.add(this.jMenu1);
		this.jMenu2.setMnemonic('g');
		this.jMenu2.setText("Algorithm");
		this.KmeansItem6.setAccelerator(KeyStroke.getKeyStroke(75, 8));
		this.KmeansItem6.setText("K-means");
		KmeansItem6.addActionListener(listener);     
		this.jMenu2.add(this.KmeansItem6);

		this.HierarchicalItem7.setAccelerator(KeyStroke.getKeyStroke(73, 8));
		this.HierarchicalItem7.setText("Hierarchical");
		HierarchicalItem7.addActionListener(listener);      
		this.jMenu2.add(this.HierarchicalItem7);

		this.jMenuBar1.add(this.jMenu2);

		this.jMenu3.setMnemonic('v');
		this.jMenu3.setText("View");

		this.smallMetaItem8.setAccelerator(KeyStroke.getKeyStroke(77, 8));
		this.smallMetaItem8.setIcon(new ImageIcon(getClass().getResource("/meta16.png")));
		this.smallMetaItem8.setText("Meta Data");
		smallMetaItem8.addActionListener(listener);      

		this.jMenu3.add(this.smallMetaItem8);

		this.smallDataItem9.setAccelerator(KeyStroke.getKeyStroke(84, 8));
		this.smallDataItem9.setIcon(new ImageIcon(getClass().getResource("/data16.png")));
		this.smallDataItem9.setText("Data ");
		smallDataItem9.addActionListener(listener);      
		this.jMenu3.add(this.smallDataItem9);

		this.smallChartItem10.setAccelerator(KeyStroke.getKeyStroke(67, 8));
		this.smallChartItem10.setIcon(new ImageIcon(getClass().getResource("/chart16.png")));
		this.smallChartItem10.setText("Charts");
		smallChartItem10.addActionListener(listener);       
		this.jMenu3.add(this.smallChartItem10);

		this.smallReportItem11.setAccelerator(KeyStroke.getKeyStroke(82, 8));
		this.smallReportItem11.setIcon(new ImageIcon(getClass().getResource("/report16.png")));
		this.smallReportItem11.setText("Report");
		smallReportItem11.addActionListener(this);       
		this.jMenu3.add(this.smallReportItem11);

		this.jMenuBar1.add(this.jMenu3);

		this.jMenu4.setMnemonic('h');
		this.jMenu4.setText("Help");

		this.stanaItem12.setAccelerator(KeyStroke.getKeyStroke(78, 8));
		this.stanaItem12.setText("Stana Tutorial");
		stanaItem12.addActionListener(listener);        
		this.jMenu4.add(this.stanaItem12);

		this.aboutStana13.setAccelerator(KeyStroke.getKeyStroke(66, 8));
		this.aboutStana13.setText("About Stana");
		aboutStana13.addActionListener(listener);        
		this.jMenu4.add(this.aboutStana13);

		this.jMenuBar1.add(this.jMenu4);

		setJMenuBar(this.jMenuBar1);

		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(6, 6, 6).addComponent(this.jToolBar1, -2, -1, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jToolBar2, -2, 266, -2)).addGroup(layout.createSequentialGroup().addGap(228, 228, 228).addComponent(this.bigCsvButton3).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.bigDbfButton11).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.bigOpenButton12))).addContainerGap(48, 32767)));
		layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(this.jToolBar2, -2, -1, -2).addGap(184, 184, 184).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.bigCsvButton3).addComponent(this.bigDbfButton11)).addComponent(this.bigOpenButton12, GroupLayout.Alignment.TRAILING))).addComponent(this.jToolBar1, -2, -1, -2)).addContainerGap(124, 32767)));

		pack();
	}


	private void initComponentsChartView()
	{
		this.remove(bigCsvButton3);
		this.remove(bigDbfButton11);
		this.remove(bigOpenButton12);
		repaint();
	}
	
	private void initComponentsChartsView(){
		
		lchart=new JLabel("SELECT CHART");
		lchart.setBounds(5,40,180,45);
		lchart.setLocation(20, 20);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lchart.setFont(font);
		chartsViewPanel.add(lchart);

		chart = new JComboBox(chartdiagram);
		chart.setName("ChartVal");
		chart.setBounds(90,40,200,30);
		chart.setLocation(20, 50);
		chart.addItemListener(this);
		chartsViewPanel.add(chart);


		lselect=new JLabel("SELECT ALGORITHM");
		lselect.setBounds(5,100,180,45);
		lselect.setLocation(20,80);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lselect.setFont(font);
		chartsViewPanel.add(lselect);

		algorithm=new JComboBox(algoVal);
		algorithm.setName("AlgorithmVal");
		algorithm.setBounds(90,100,200,30);
		algorithm.setLocation(20,110);
		algorithm.addItemListener(this);
		chartsViewPanel.add(algorithm);

		lconfig=new JLabel("Chart Configuration");
		lconfig.setBounds(5,110,200,25);
		lconfig.setLocation(20,145);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lconfig.setFont(font);
		chartsViewPanel.add(lconfig);
		/*
		ltitle=new JLabel("Title");
		ltitle.setBounds(5,220,80,25);
		ltitle.setLocation(20,165);
		font=new Font("Times New Roman",Font.ITALIC,18);
		ltitle.setFont(font);
		chartsViewPanel.add(ltitle);
		*/
		title=new JTextField("Enter Title");
		title.setBounds(90,130,200,30);
		title.setLocation(20,170);
		//font=new Font("Times New Roman",Font.ITALIC,18);
		//title.setFont(font);
		chartsViewPanel.add(title);
		/*
		xaxis1 = new JLabel("X-axisname");
		xaxis1.setBounds(5,280,100,25);
		xaxis1.setLocation(20,195);
		font=new Font("Times New Roman",Font.ITALIC,18);
		xaxis1.setFont(font);
		chartsViewPanel.add(xaxis1);
		*/
		
		xaxis=new JTextField("Enter X-axisname");
		xaxis.setBounds(90,160,200,30);
		xaxis.setLocation(20, 200);
		//font=new Font("Times New Roman",Font.ITALIC,18);
		//xaxis.setFont(font);
		chartsViewPanel.add(xaxis);
		/*
		yaxis1=new JLabel("Y-axisname");
		yaxis1.setBounds(5,340,100,25);
		yaxis1.setLocation(20,225);
		font=new Font("Times New Roman",Font.ITALIC,18);
		yaxis1.setFont(font);
		chartsViewPanel.add(yaxis1);
		*/
		yaxis=new JTextField("Enter Y-axisname");
		yaxis.setBounds(90,190,200,30);
		yaxis.setLocation(20,230);
		//font=new Font("Times New Roman",Font.ITALIC,18);
		//yaxis.setFont(font);
		chartsViewPanel.add(yaxis);

		chartsViewPanel.setSize(250,300);
		chartsViewPanel.setLocation(0, 45);
		chartsViewPanel.setBorder(BorderFactory.createBevelBorder(0));
		this.add(chartsViewPanel);
		this.repaint();

		
	}

	private void initComponentsAddition32View()
	{
		JLabel algoname = null;
		if (algoNameSelected != null) {
			String algoLabelName = "Algorithm : " + algoNameSelected;
			algoname=new JLabel( algoLabelName );
		}

		algoname.setBounds(10,5,200,25);
		algoname.setLocation(10,40);
		font = new Font("Times New Roman",Font.ITALIC,18);
		algoname.setFont(font);
		panel32.add(algoname);

		// Here we have to add the variable list in choice box and keep selections by multi
		if (attributesValue != null) {
			JLabel attributes = new JLabel("Attributes :");
			attributes.setBounds(10,5,100,25);
			attributes.setLocation(10,70);
			font=new Font("Times New Roman",Font.ITALIC,18);
			attributes.setFont(font);
			panel32.add(attributes);
			JComboBox attributeVals = new JComboBox(attributesValue);
		    attributeVals.setName("AttributesVal");
			attributeVals.setBounds(170,120,220,30);
			attributeVals.setLocation(120,70);
			attributeVals.addItemListener(this);
			panel32.add(attributeVals);
		}
		JLabel ldistance = null;
		if (distanceValSelected != null) {
			String distanceName = "Distance Measures : " + distanceValSelected ;
			ldistance = new JLabel(distanceName);
		}
		ldistance.setBounds(10,120,400,30);
		ldistance.setLocation(10,105);
		font=new Font("Times New Roman",Font.ITALIC,18);
		ldistance.setFont(font);
		panel32.add(ldistance);
		
		JComboBox distance=new JComboBox(distanceVal);
		distance.setName("DistanceVal");
		distance.setBounds(170,120,200,30);
		distance.setLocation(10,140);
		distance.addItemListener(this);
		panel32.add(distance);

		JLabel mincluster=new JLabel("Minimum Of Cluster	:");
		mincluster.setBounds(170,155,220,30);
		mincluster.setLocation(10,175);
		font = new Font("Times New Roman",Font.ITALIC,18);
		mincluster.setFont(font);
		panel32.add(mincluster);

		JComboBox minClusterVal = new JComboBox(minClusterValue);
		minClusterVal.setName("MinCluster");
		minClusterVal.setBounds(170,120,220,30);
		minClusterVal.setLocation(240,175);
		minClusterVal.addItemListener(this);
		panel32.add(minClusterVal);


		JLabel maxcluster=new JLabel("Maximum Of Cluster:");
		maxcluster.setBounds(10,190,220,30);
		maxcluster.setLocation(10,210);
		maxcluster.setFont(font);
		panel32.add(maxcluster);

		JComboBox maxClusterVal = new JComboBox(maxClusterValue);
		maxClusterVal.setName("MaxCluster");
		maxClusterVal.setBounds(170,120,220,30);
		maxClusterVal.setLocation(240,210);
		panel32.add(maxClusterVal); 

		ok=new JButton("OK");
		ok.setName("OKView32");
		ok.setBounds(265,40,100,30);
		ok.setLocation(370,40);
		ok.addActionListener(this);
		font=new Font("Times New Roman",Font.ITALIC,18);
		ok.setFont(font);
		panel32.add(ok); 

		cancel=new JButton("Cancel");
		cancel.setName("CancelView32");
		cancel.setBounds(265,75,100,30);
		cancel.setLocation(370, 80);
		cancel.addActionListener(this);
		font=new Font("Times New Roman",Font.ITALIC,18);
		cancel.setFont(font);
		panel32.add(cancel); 
		panel32.setSize(500,350);
		panel32.setLocation(0,400);
		//Border blackline = BorderFactory.createLineBorder(Color.black);
		// Make it look embossed
		//panel32.setBorder(BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(0), "ClusterDetails"));
		
		clusterDetail.add(panel32);
		clusterDetail.setSize(500,350);
		clusterDetail.repaint();
		clusterDetail.setVisible(true);

	}
	
	public class ButtonActionListener implements ActionListener
	{

		Component parent;
		JScrollPane filePane;
		JTable dataTable;
		
		public ButtonActionListener(Component parent, JScrollPane filePane) {
			this.parent = parent;
			this.filePane = filePane;
		}
		public  JTable getDataTableVal() {
			return dataTable;
		}
		public void actionPerformed(ActionEvent e)	{
			System.out.println(" the e object and the parent " + parent.toString());
			if (e.getSource().toString().contains("javax.swing.JButton")) {
				JButton test = (JButton)e.getSource();
				String buttonName = test.getName();
				if (buttonName.equalsIgnoreCase("OKView32")) {
					System.out.println(" OK View Had been clicked");
					//System.out.println("vl\n");
					// Here what we have to do , we have to call on the algo and 
					// call on the corresponding algo.
					// then call on city/ etc
				} else if (buttonName.equalsIgnoreCase("CancelView32")) {
					System.out.println(" the cancel view had been clicked");
				}
				if(buttonName.equals("csvButton1") || (buttonName.equals("bigCsvButton3"))) {
					// Here we have to write the file opening for the csv
					JFileChooser fileopen = new JFileChooser();
					FileNameExtensionFilter filter = new FileNameExtensionFilter("csv files", "csv");
					fileopen.addChoosableFileFilter(filter);
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					panel.show();
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						ArrayList<String[]> readData = readCSVFile(file);
						int columnLength = readData.get(0).length;
						attributesValue = new String[columnLength];
						for (int i = 0; i < columnLength; i++) {
							attributesValue[i] = "Attribute " + (i + 1);
						}
						
						dataTable = new JTable(new MyModel(readData, attributesValue));
						JFrame frame = (JFrame) parent;
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						filePane.setViewportView(dataTable);
						filePane.setLocation(600, 50);
						filePane.setSize(600,500);
						frame.add(filePane, BorderLayout.CENTER);
						frame.setSize(1400, 1000);
						frame.setVisible(true);

					}

				} else if (buttonName.equals("dbfButton5") || buttonName.equals("bigDbfButton11")) {
					JFileChooser fileopen = new JFileChooser();
					FileNameExtensionFilter filter = new FileNameExtensionFilter("dbf files", "dbf");
					fileopen.addChoosableFileFilter(filter);
					JFrame frame = (JFrame) parent;
					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						dataTable = readDBFFile(file);
						System.out.println(" the data table " + dataTable.getColumnName(0));
						filePane.setViewportView(dataTable);
						filePane.setLocation(600, 50);
						filePane.setSize(600,500);
						frame.add(filePane, BorderLayout.CENTER);
						frame.setSize(1400, 1000);
						frame.setVisible(true);
					}

					// Here the DBF click operation to go
				} else if (buttonName.equals("openButton4") || buttonName.equals("bigOpenButton12")) {
					// Here we have to write the file opening for the csv
					JFileChooser fileopen = new JFileChooser();
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					panel.show();
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						ArrayList<String[]> readData = readCSVFile(file);
						int columnLength = readData.get(0).length;
						attributesValue = new String[columnLength];
						for (int i = 0; i < columnLength; i++) {
							attributesValue[i] = "Attribute " + (i + 1);
						}

						dataTable = new JTable(new MyModel(readData, attributesValue));
						JFrame frame = new JFrame();
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						JScrollPane scrollPane = new JScrollPane(dataTable);
						frame.add(scrollPane, BorderLayout.CENTER);
						frame.setSize(1000, 350);
						frame.setVisible(true);
					}
				} else if (buttonName.equals("saveButton13")) {
					JFileChooser saveOperation = new JFileChooser();
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					saveOperation.setDialogTitle("Specify a file to save");  
					int userSelection = saveOperation.showSaveDialog(panel); 
					if (userSelection == JFileChooser.APPROVE_OPTION) {    
						File fileToSave = saveOperation.getSelectedFile();    
						System.out.println("Save as file: " + fileToSave.getAbsolutePath());
					}
				} else if (buttonName.equals("printButton10")) {
					PrinterJob job = PrinterJob.getPrinterJob();         
					job.setPrintable((Printable) this);        
					boolean ok = job.printDialog();         
					if (ok) {             
						try {                  
							job.print();             
						} catch (PrinterException ex) {   
							/* The job did not successfully complete */             
						}        
					}
				} else if (buttonName.equals("metaButton6")) {
					// Schema view
					int columnCount = dataTable.getColumnCount();
					int rowCount = dataTable.getRowCount();
					JLabel [] columnValueArr = null;
					for (int k = 0; k < 1; k++) {
						for (int i = 0; i < columnCount; i++) {
							String type = "";
							if (dataTable.getValueAt(k,i) instanceof Integer) {
								// How to execute the value of the Integer
								type = "Integer";
							} else if (dataTable.getValueAt(k,i) instanceof String) {
								type = "Varchar";
							} else if (dataTable.getValueAt(k, i) instanceof Double) {
								type = "Double";
							}
							columnsTypeList[i] = type + ":" + attributesValue[i];

							columnValueArr[i] = new JLabel(columnsTypeList[i]);
							columnValueArr[i].setBounds(10,5,100,25);
							columnValueArr[i].setLocation(10,i*70);
							font=new Font("Times New Roman",Font.ITALIC,18);
							columnValueArr[i].setFont(font);
							panelSchema.add(columnValueArr[i]);
							
						}
						panelSchema.setSize(500,350);
						panelSchema.setLocation(500, 10);
						Border blackline = BorderFactory.createLineBorder(Color.black);
						panelSchema.setBorder(BorderFactory.createTitledBorder(blackline, "f"));
						JFrame frameMain = (JFrame)this.parent;
						frameMain.add(panelSchema);

					}
					
					System.out.println(" the metaButton6 clicked");				

				} else if (buttonName.equals("dataButton7")) {
					System.out.println(" the dataButton7 clicked");				

				} else if (buttonName.equals("chartsButton8")) {
					System.out.println(" the charts view clicked");
					initComponentsChartView();
					initComponentsChartsView();
					// get the value of the chart.
					
				} else if (buttonName.equals("reportButton9")){
					System.out.println(" Testing ito s reportsButton9");
				}
				
			}
			if (e.getSource().toString().contains("javax.swing.JMenuItem")) {
				JMenuItem test = (JMenuItem)e.getSource();
				String menuName =  test.getName();
				if (menuName.equals("smallCsvItem4")) {
					// Here we have to write the file opening for the csv
					JFileChooser fileopen = new JFileChooser();
					FileNameExtensionFilter filter = new FileNameExtensionFilter("csv files", "csv");
					fileopen.addChoosableFileFilter(filter);
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					panel.show();
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						ArrayList<String[]> readData = readCSVFile(file);
						int columnLength = readData.get(0).length;
						attributesValue = new String[columnLength];
						for (int i = 0; i < columnLength; i++) {
							attributesValue[i] = "Attribute " + (i + 1);
						}

						dataTable = new JTable(new MyModel(readData, attributesValue));
						JFrame frame = new JFrame();
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						JScrollPane scrollPane = new JScrollPane(dataTable);
						frame.add(scrollPane, BorderLayout.CENTER);
						frame.setSize(1000,350);
						frame.setVisible(true);
					}

				} else if (menuName.equals("smallDbfItem5")) {
					JFileChooser fileopen = new JFileChooser();
					FileNameExtensionFilter filter = new FileNameExtensionFilter("dbf files", "dbf");
					fileopen.addChoosableFileFilter(filter);
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						dataTable = readDBFFile(file);
						System.out.println(" the dataTable Size " + dataTable.size());
						JFrame frame = new JFrame();
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						JScrollPane scrollPane = new JScrollPane(dataTable);
						frame.add(scrollPane, BorderLayout.CENTER);
						frame.setSize(1000, 350);
						frame.setVisible(true);
					}
				} else if (menuName.equals("smallOpenItem1")) {
					// Here we have to write the file opening for the csv
					JFileChooser fileopen = new JFileChooser();
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());
					panel.show();
					int ret = fileopen.showDialog(panel, "Open file");
					if (ret == JFileChooser.APPROVE_OPTION) {
						File file = fileopen.getSelectedFile();
						ArrayList<String[]> readData = readCSVFile(file);
						int columnLength = readData.get(0).length;
						attributesValue = new String[columnLength];
						for (int i = 0; i < columnLength; i++) {
							attributesValue[i] = "Attribute " + (i + 1);
						}
						dataTable = new JTable(new MyModel(readData, attributesValue));
						JFrame frame = new JFrame();
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						JScrollPane scrollPane = new JScrollPane(dataTable);
						frame.add(scrollPane, BorderLayout.CENTER);
						frame.setSize(1000, 350);
						frame.setVisible(true);
					}

				} else if (menuName.equals("smallSaveItem14")) {
					System.out.println(" the smallSaveItem14 clicked");				
					JFileChooser saveOperation = new JFileChooser();
					JPanel panel = new JPanel();
					panel.setLayout(new BorderLayout());

					saveOperation.setDialogTitle("Specify a file to save");  
					int userSelection = saveOperation.showSaveDialog(panel); 
					if (userSelection == JFileChooser.APPROVE_OPTION) {    
						File fileToSave = saveOperation.getSelectedFile();    
						System.out.println("Save as file: " + fileToSave.getAbsolutePath());}

				} else if (menuName.equals("smallPrintItem2")) {
					System.out.println(" the smallPrintItem2 clicked");				

				} else if (menuName.equals("exitMenuItem3")) {
					System.exit(0);

				} else if (menuName.equals("KmeansItem6")) {
					System.out.println(" the KmeansItem6 clicked");				

				} else if (menuName.equals("HierarchicalItem7")) {
					System.out.println(" the HierarchicalItem7 clicked");				

				} else if (menuName.equals("smallMetaItem8")) {
					System.out.println(" the smallMetaItem8 clicked");				

				} else if (menuName.equals("smallDataItem9")) {
					System.out.println(" the smallDataItem9 clicked");				

				} else if (menuName.equals("smallChartItem10")) {
					System.out.println(" the smallChartItem10 clicked");				

				} else if (menuName.equals("smallReportItem11")) {
					System.out.println(" the smallReportItem11 clicked");				

				} else if (menuName.equals("stanaItem12")) {
					System.out.println(" the stanaItem12 clicked");				

				} else if (menuName.equals("aboutStana13")) {
					System.out.println(" the aboutStana13 clicked");				

				}

			}
		}
		private JTable readDBFFile(File file) {
			// TODO Auto-generated method stub
			// Here we have to read the file
			JTable jTable1 = null;
			try {
				InputStream inputStream  = new FileInputStream(file); // take dbf file as program argument
				DBFReader reader = new DBFReader( inputStream); 
				int numberOfFields = reader.getFieldCount();
				String[] columnNames = new String[numberOfFields];
				attributesValue = new String[numberOfFields];
				int numberOfRecords = reader.getRecordCount();
				for( int i=0; i<numberOfFields; i++) {
					// Put in the table the headings
					columnNames[i] = reader.getField( i).getName();
					attributesValue[i] = columnNames[i];
					// add the column headings here

				}
				Object[] rowObjects;
				Object[][] data = new Object[numberOfRecords][numberOfFields];
				int j = 0;
				while( (rowObjects = reader.nextRecord()) != null) {
					for( int i=0; i<rowObjects.length; i++)
					{
						data[j][i] = rowObjects[i];

					} 
					j++;
				}
				jTable1 = new JTable(data, columnNames);                      
				inputStream.close();
			} catch( DBFException e) {

				System.out.println( e.getMessage());
			} catch( IOException e) {
				System.out.println( e.getMessage());
			}
			return jTable1;
		}
		class MyModel extends AbstractTableModel {
			private String[] columnNames = {
					"Attribute 1", 
					"Attribute 2", 
					"Attribute 3", 
					"Attribute 4", 
					"Attribute 5", 
			"Attribute 6"};
			private ArrayList<String[]> Data =  null;

			MyModel(ArrayList<String[]> DataIn, String[] columnNames) {
				Data =  new ArrayList<String[]>(DataIn.size());	
				this.columnNames = columnNames;
				Data = DataIn;
			}
			public void AddCSVData(ArrayList<String[]> DataIn) {
				this.Data = DataIn;
				this.fireTableDataChanged();
			}
			@Override
			public int getColumnCount() {
				return columnNames.length;//length;
			}
			@Override
			public int getRowCount() {
				return Data.size();
			}
			@Override
			public String getColumnName(int col) {
				return columnNames[col];
			}
			@Override
			public Object getValueAt(int row, int col)
			{
				return Data.get(row)[col];

			}      
		}

		private ArrayList<String[]> readCSVFile(File file) {
			// TODO Auto-generated method stub
			System.out.println(" the file passed " + file.getAbsolutePath());
			ArrayList<String[]> dataList = new ArrayList<String[]>(6);
			String[] OneRow = null;

			try {
				BufferedReader brd = new BufferedReader (new FileReader(file));

				while (brd.readLine() != null) {
					String st = brd.readLine();
					OneRow = st.split(","); 
					dataList.add(OneRow);
				} // end of while
				System.out.println(" the number of Columns " + OneRow.length);
			} // end of try
			catch (Exception e) {
				String errmsg = e.getMessage();
				System.out.println ("File not found:" +errmsg);
			} // end of Catch                   
			return dataList;
		}// end of ReadFile method

	}




	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				new Welcome().setVisible(true);
			}
		});
	}


	@Override
	public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
			throws PrinterException {
		boolean horizontal = true;
		double pageWidth = pageFormat.getImageableWidth();   
		double pageHeight = pageFormat.getImageableHeight();   
		double pageX = pageFormat.getImageableX();   
		double pageY = pageFormat.getImageableY();   
		int columns = (int)Math.ceil(this.getWidth() / pageWidth);   
		int rows = (int)Math.ceil(this.getHeight() / pageHeight);   

		if (pageIndex >= rows * columns)   
		{   
			return NO_SUCH_PAGE;   
		}   
		int column = (horizontal ? pageIndex % columns : pageIndex / rows);   
		int row = (horizontal ? pageIndex / columns : pageIndex % rows);   

		graphics.translate(   
				(int)(pageX - column * pageWidth), (int)(pageY - row * pageHeight)   
				);   
		RepaintManager m = RepaintManager.currentManager(this);   
		boolean b = m.isDoubleBufferingEnabled();   
		m.setDoubleBufferingEnabled(false);   
		this.printAll(graphics);   
		m.setDoubleBufferingEnabled(b);   
		return PAGE_EXISTS;   

	}

	@Override
	public void actionPerformed(ActionEvent e) {

		this.remove(filePane);
		JButton test = (JButton)e.getSource();
		String buttonName = test.getName();
		if (buttonName.equalsIgnoreCase("OKView32")) {
			clusterDetail.dispose();
			//System.out.println("ok button");
			callTheClusteringAlgo();
			// forth screen call
		} else if (buttonName.equalsIgnoreCase("CancelView32")) {
			System.out.println(" the cancel view had been clicked");
			// continue
		}
		/*
		this.initComponentsChartView();
		this.setTitle("Chart View");
		lchart=new JLabel("Chart");
		lchart.setBounds(5, 40,80,25);
		lchart.setLocation(45, 40);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lchart.setFont(font);
		panel.add(lchart);

		chart = new JComboBox(chartdiagram);
		chart.setName("ChartVal");
		chart.setBounds(90,40,200,30);
		chart.setLocation(200, 40);
		chart.addItemListener(this);
		panel.add(chart);


		lselect=new JLabel("Select");
		lselect.setBounds(5,100,80,25);
		lselect.setLocation(45,90);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lselect.setFont(font);
		panel.add(lselect);

		algorithm=new JComboBox(algoVal);
		algorithm.setName("AlgorithmVal");
		algorithm.setBounds(90,100,200,30);
		algorithm.setLocation(200,90);
		algorithm.addItemListener(this);
		panel.add(algorithm);

		lconfig=new JLabel("Chart Configuration");
		lconfig.setBounds(5,100,200,25);
		lconfig.setLocation(45,130);
		font=new Font("Times New Roman",Font.ITALIC,18);
		lconfig.setFont(font);
		panel.add(lconfig);

		ltitle=new JLabel("Title");
		ltitle.setBounds(5,220,80,25);
		ltitle.setLocation(45,165);
		font=new Font("Times New Roman",Font.ITALIC,18);
		ltitle.setFont(font);
		panel.add(ltitle);

		title=new JTextField("Enter Title");
		title.setBounds(90,130,200,30);
		title.setLocation(200,165);
		font=new Font("Times New Roman",Font.ITALIC,18);
		title.setFont(font);
		panel.add(title);

		xaxis1 = new JLabel("X-axisname");
		xaxis1.setBounds(5,280,100,25);
		xaxis1.setLocation(45,195);
		font=new Font("Times New Roman",Font.ITALIC,18);
		xaxis1.setFont(font);
		panel.add(xaxis1);

		xaxis=new JTextField("Enter X-axisname");
		xaxis.setBounds(90,160,200,30);
		xaxis.setLocation(200, 195);
		font=new Font("Times New Roman",Font.ITALIC,18);
		xaxis.setFont(font);
		panel.add(xaxis);

		yaxis1=new JLabel("Y-axisname");
		yaxis1.setBounds(5,340,100,25);
		yaxis1.setLocation(45,225);
		font=new Font("Times New Roman",Font.ITALIC,18);
		yaxis1.setFont(font);
		panel.add(yaxis1);

		yaxis=new JTextField("Enter Y-axisname");
		yaxis.setBounds(90,190,200,30);
		yaxis.setLocation(200,225);
		font=new Font("Times New Roman",Font.ITALIC,18);
		yaxis.setFont(font);
		panel.add(yaxis);

		panel.setSize(500,400);
		this.add(panel);
		this.repaint();
		*/
	}

	@Override
	public void itemStateChanged(ItemEvent e) {

		JComboBox test = (JComboBox)e.getSource();
		String comboBoxName = test.getName();
		System.out.println(" the comboBoxName " + comboBoxName);
		
		if (comboBoxName.equalsIgnoreCase("AttributesVal")) {
			attributesList.addElement(test.getSelectedItem());
			System.out.println("index list: "+indexList.size());
			indexList.addElement(test.getSelectedIndex());
		}
		
		if (comboBoxName.equalsIgnoreCase("AlgorithmVal")) {
			algoNameSelected = test.getSelectedItem().toString();
			if (algoNameSelected.equalsIgnoreCase("K-means")) {
				initComponentsAddition32View();
				dataTableValue = ((ButtonActionListener) listener).getDataTableVal();
				System.out.println(" the value of the row count " + dataTableValue.getRowCount());			
			} else if (algoNameSelected.equalsIgnoreCase("Hierarchical")) {
				initComponentsAddition32View();
				dataTableValue = ((ButtonActionListener) listener).getDataTableVal();
				System.out.println(" the value of the row count " + dataTableValue.getRowCount());
			}
		} 
		
		if (comboBoxName.equalsIgnoreCase("DistanceVal")) {
			distanceValSelected = test.getSelectedItem().toString();
			if (distanceValSelected.equalsIgnoreCase("Euclidean Distance")) {
				initComponentsAddition32View();
			} else if (distanceValSelected.equalsIgnoreCase("City Block Distance")) {
				initComponentsAddition32View();
			}
		} 
		
		if (comboBoxName.equalsIgnoreCase("MinCluster")) {
			numberOfMinClusters = test.getSelectedItem().toString();
			initComponentsAddition32View();
		} 
		
		if (comboBoxName.equalsIgnoreCase("MinCluster")) {
			numberOfMaxClusters = test.getSelectedItem().toString();
			initComponentsAddition32View();
		} 

		if (comboBoxName.equalsIgnoreCase("ChartVal")) {
			chartNameSelected = test.getSelectedItem().toString();
			
			//System.out.println(chartNameSelected+ " <--- Chart name");
			
			if (test.getSelectedItem().toString().equalsIgnoreCase("Pie Chart")) {
				System.out.println(" the value selected is Pie Chart");
			} else if (test.getSelectedItem().toString().equalsIgnoreCase("Histogram")) {
				System.out.println(" the value selected is Histogram");
			} else if (test.getSelectedItem().toString().equalsIgnoreCase("Area Chart")) {
				System.out.println(" the value selected is Area Chart");
			} else if (test.getSelectedItem().toString().equalsIgnoreCase("Scatter")) {
				System.out.println(" the value selected is Scatter");
			}
		}
		
		//if else: incorrect
		/*if (algoNameSelected.equalsIgnoreCase("Select Algorithm") || 
				chartNameSelected.equalsIgnoreCase("") ||
				numberOfMaxClusters.equalsIgnoreCase("") ||
				numberOfMinClusters.equalsIgnoreCase("") ||
				distanceValSelected.equalsIgnoreCase("") || 
				(attributesList.size() == 0)) {
			// enter the value of the JOptionPane data
			JOptionPane.showMessageDialog(this, 
					"Please make sure you entered the algorithm Name, Chart Name, Number of Max clusters, Number of Max clusters, distanceVal Selected");
			return;
				
		}*/
		//System.out.println("Thuoc Tinh: "+attributesList.size());
		//if (attributesList.size() >= 4) {
		//	callTheClusteringAlgo();
		//}
	}

	private void callTheClusteringAlgo() {
		// TODO Auto-generated method stub
		int rowCount = dataTableValue.getRowCount();
		Object column1 =  indexList.get(0);
		Object column2 =  indexList.get(2);
		index1 =  Integer.parseInt(column1.toString());
		index2 =  Integer.parseInt(column2.toString());
		System.out.println(" the algo value selected " + algoNameSelected);
		//K-means
		//Hierarchical
		if (algoNameSelected.equalsIgnoreCase("K-means")) {
			List<stanaGUI.KMeans.Item> input = new ArrayList<stanaGUI.KMeans.Item>();
			for (int i = 0; i < rowCount; i++) {
				double param1 = Double.parseDouble(dataTableValue.getValueAt(i,index1).toString());
				double param2 = Double.parseDouble(dataTableValue.getValueAt(i, index2).toString());
				System.out.println(" the data Table Value " + 
						Double.parseDouble(dataTableValue.getValueAt(i,index1).toString()) + " " +
						Double.parseDouble(dataTableValue.getValueAt(i, index2).toString()));
				// Data added here
				stanaGUI.KMeans.Item item= new stanaGUI.KMeans.Item(param1, param2);
				int numCol = dataTableValue.getColumnCount();
				String rowToString = "";
				for(int k=0;k<numCol;k++){
					
					rowToString = rowToString+dataTableValue.getValueAt(i,k).toString()+" , ";
				}
				
				
				input.add(item);
			}
			//
			//System.out.println("Min: "+numberOfMinClusters);
			//
			//System.out.println("dau xanh rau ma: "+(Integer.parseInt(numberOfMinClusters) + 
			//		Integer.parseInt(numberOfMaxClusters)/2));
			
			AlgoKMeans algoKMeans = new AlgoKMeans(
					(Integer.parseInt(numberOfMinClusters) + 
					Integer.parseInt(numberOfMaxClusters)/2));  // we request 3 clusters
			List<stanaGUI.KMeans.Cluster> clusters2 = algoKMeans.runAlgorithm(input);
			// Print the results
			for(stanaGUI.KMeans.Cluster cluster : clusters2) {
				//System.out.println(clusters2.get(0).size());
				System.out.println(cluster.toString());
			}
			if (distanceValSelected.equalsIgnoreCase("Euclidean Distance")) {
				// With the distanceValSelected, we have to pass algo of that 
				int dataSize = input.size();
				euclideanVal = 0;
				for (int i = 0; i < dataSize; i++) {
					euclideanVal += (input.get(i).getValue1() * input.get(i).getValue1() + input.get(i).getValue2() * input.get(i).getValue2());
				}
			} else if (distanceValSelected.equalsIgnoreCase("City Block Distance")) {
				// with the value of this , we have to pass the algo of that
				int dataSize = input.size();
				cityBlockVal = 0;
				for (int i = 0; i < dataSize; i++) {
					cityBlockVal = input.get(i).getValue1() + input.get(i).getValue2();
				}
			}
			GraphicalRepresentationKmeans graph = new GraphicalRepresentationKmeans();

			if (chartNameSelected.equalsIgnoreCase("Pie Chart")) {
				//System.out.println("kick thuoc "+clusters2.size());
				System.out.println(" the value selected is Pie Chart");
				JPanel panel = graph.PieChart("Stana", "Cluster of Product", clusters2);
				JFrame graphFrame = (JFrame)this;
				
				graphFrame.setVisible(true);
				panel.setLocation(400, 50);
				panel.setSize(800,600);
				graphFrame.add(panel);
				graphFrame.repaint();
			} else if (chartNameSelected.equalsIgnoreCase("Histogram")) {
				
				System.out.println(" the value selected is Histogram");
				JPanel panel = graph.Histogram("Stana", clusters2);
				JFrame graphFrame = (JFrame)this;
				graphFrame.setVisible(true);
				panel.setLocation(600, 50);
				panel.setSize(600,500);
				graphFrame.add(panel);
				graphFrame.repaint();
				System.out.println(" the value selected is Histogram");
				
			} else if (chartNameSelected.equalsIgnoreCase("Area Chart")) {
				
				JPanel panel = graph.AreaChart("Stana", clusters2);
				JFrame graphFrame = (JFrame)this;
				graphFrame.setVisible(true);
				panel.setLocation(600, 50);
				panel.setSize(600,500);
				graphFrame.add(panel);
				graphFrame.repaint();
				System.out.println(" the value selected is Area Chart");

			} else if (chartNameSelected.equalsIgnoreCase("Scatter")) {

				System.out.println(" the value selected is Scatter");
				JPanel panel = graph.ScatterChart("Stana", clusters2);
				JFrame graphFrame = (JFrame)this;
				graphFrame.setVisible(true);
				panel.setLocation(600, 50);
				panel.setSize(600,500);
				graphFrame.add(panel);
				graphFrame.repaint();
			
			}
		} else if (algoNameSelected.equalsIgnoreCase("Hierarchical")) {

			List<stanaGUI.Hierarchical.Item> input = new ArrayList<stanaGUI.Hierarchical.Item>();
			for (int i = 0; i < rowCount; i++) {
				double param1 = Double.parseDouble(dataTableValue.getValueAt(i,index1).toString());
				double param2 = Double.parseDouble(dataTableValue.getValueAt(i, index2).toString());
				input.add(new Item(param1,param2));  
			}
			AlgoHierarchicalClustering algoH = new AlgoHierarchicalClustering(2.0,5.6);
			List<Cluster> clusters = algoH.runAlgorithm(input);
			// print the results
			for(Cluster cluster : clusters){
				System.out.println(cluster.toString());
			}
		}
	}
}